package sharping.appilog.Adapter;

import java.util.ArrayList;

import sharping.appilog.R;
import sharping.appilog.DataTree.HaveCouponData;
import sharping.appilog.ListItem.HaveCouponItem;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class RHaveCouponAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<HaveCouponData> items;
	private LayoutInflater inflater;
	
	public RHaveCouponAdapter(Context context, ArrayList<HaveCouponData> items, LayoutInflater inflater) {
		this.context = context;
		this.items = items;
		this.inflater = inflater;
	}
	
	public void setItems(ArrayList<HaveCouponData> items) {
		this.items = items;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		HaveCouponItem v;
		
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.list_coupon_type1, null);
			v = new HaveCouponItem(context, convertView);
			
			convertView.setTag(v);
		} else {
			v = (HaveCouponItem) convertView.getTag();
		}
		
		v.setItem(items.get(position));
		v.setParam();
		
		return convertView;
	}

	@Override
	public void notifyDataSetChanged() {
		// TODO Auto-generated method stub
		super.notifyDataSetChanged();
	}
}
